package cn.com.kh;

import cn.com.elite.EliteBean;
import cn.com.elite.Util;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @projectName: ngsapitask-sw
 * @package: cn.com.kh
 * @className: KHSW5GUtil
 * @author: LiJT
 * @description: TODO 深圳水务5G客制化工具类
 * @date: 2022-10-25 16:57
 * @version: 1.0
 */

public class KHSW5GUtil {
    private static final Log log = LogFactory.getLog(KHSW5GUtil.class);

    public static String sendTrigger5Gmsg(String url, String serverRoot, String access_token, String templateId, String serviceId, String mobileNo) throws Exception {

        // 查出传真发送的地址
        Map<String, String> headParams = new HashMap<String, String>();
        headParams.put("Content-Type", "application/json");
        headParams.put("Authorization", "Bearer " + access_token);
        headParams.put("serverRoot", serverRoot);

        JSONObject postJson = new JSONObject();
        postJson.put("templateId", templateId);
        postJson.put("serviceId", serviceId);

        JSONArray mobileNos = new JSONArray();
        mobileNos.add(mobileNo);
        postJson.put("mobileNos", mobileNos);

        log.debug("5G消息触发-调用地址:" + url + " 调用参数信息:" + postJson);

        String resultInfo = Util.doHttpPostUseHead(url, postJson.toString(), "UTF-8", 120000, 0, headParams);
        log.debug("5G消息触发-调用结果:" + resultInfo);

        JSONObject resultJson = JSONObject.fromObject(resultInfo);
        String data = resultJson.getString("code");
        return data;
    }

    public static String sendDynamicTrigger5Gmsg(String url, String serverRoot, String access_token, String templateId, String serviceId, String mobileNo) throws Exception {

        // 查出传真发送的地址
        Map<String, String> headParams = new HashMap<String, String>();
        headParams.put("Content-Type", "application/json");
        headParams.put("Authorization", "Bearer " + access_token);
        headParams.put("serverRoot", serverRoot);

        JSONObject postJson = new JSONObject();
        postJson.put("templateId", templateId);
        postJson.put("serviceId", serviceId);

        JSONArray dynamicInfoArr = new JSONArray();
        JSONObject dynamicInfo = JSONObject.fromObject("{\n" + "            \"mobileNo\":\"" + mobileNo + "\",\n" + "            \"dynamicMultivariable\":[\n" + "                {\n" + "                    \"paramName\":\"param1\",\n" + "                    \"paramValue\":\"11111\"\n" + "                },\n" + "                {\n" + "                    \"paramName\":\"param2\",\n" + "                    \"paramValue\":\"22222\"\n" + "                }\n" + "            ]\n" + "        }");
        dynamicInfoArr.add(dynamicInfo);

        postJson.put("dynamicInfo", dynamicInfoArr);

        log.debug("5G消息动态变量模板触发调用地址:" + url + " 调用参数信息:" + postJson);

        String resultInfo = Util.doHttpPostUseHead(url, postJson.toString(), "UTF-8", 120000, 0, headParams);
        log.debug("5G消息动态变量模板触发调用结果:" + resultInfo);

        JSONObject resultJson = JSONObject.fromObject(resultInfo);
        String data = resultJson.getString("code");

        return data;
    }
}
